﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using YAPL.Language.Ast.Utils;

namespace YAPL.Language.Ast {
	public class ReturnExpression : Expression {
		private Expression _statement;
		public ReturnExpression(ExpressionType nodeType, Type type, Expression statement) : base(nodeType, type) {
			_statement = statement;
		}

		public ReturnExpression(ExpressionType nodeType, Type type, bool canRead, bool canWrite, Expression statement) : base(nodeType, type, canRead, canWrite) {
			_statement = statement;
		}

		[Descendant(AstVisit.BeforeCurrent)]
		public Expression Statement {
			get { return _statement; }
		}

		public override bool NodeEquals(Expression other) {
			return other is ReturnExpression;
		}

		public override bool RewriteChild(Expression child, Expression newExpression) {
			if (ReferenceEquals(_statement, child)) {
				_statement = newExpression;
				return true;
			}

			return false;
		}
	}
}
